package com.my.controller;


import com.my.bean.*;
import com.my.service.AlreadyAppointmentService;
import com.my.service.EvaluateService;
import com.my.service.ProductionService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产康评价 前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-08-25
 */
@Controller
@RequestMapping("/evaluate")
public class EvaluateController {
    @Autowired
    EvaluateService evaluateService;
    @Autowired
    ProductionService productionService;

    Logger logger=Logger.getLogger(WorkguidaceController.class);

    /**
     * 添加
     * @param evaluate
     * @return
     */
    @RequestMapping("/addEvaluate")
    @ResponseBody
    public String addEvaluate(Evaluate evaluate, HttpSession session){
        evaluate.setCreateTime(new Date().getTime());
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        evaluate.setAreaid(areaid);
      if (evaluateService.insert(evaluate)){
          logger.info("{addEvaluate|保存成功}");
          return "保存成功";
      }else{
          logger.info("{addEvaluate|保存失败}");
          return "保存失败";
      }

    }

    /**
     * 查询
     * @return
     */
    @RequestMapping("/selectEvaluate")
    @ResponseBody
    public List<Evaluate> selectEvaluate(HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        List<Evaluate> list = evaluateService.selectEvaluate(areaid,admin);
        return  list;
    }

    /**
     * 查询
     * @return
     */
    @RequestMapping("/findAllProject")
    @ResponseBody
    public List<Production> findAllProject(HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Map map=new HashMap();
        return  productionService.selectByMap(map);
    }


    /**
     * 图表
     * @return
     */
    @RequestMapping("/countEvaStar")
    @ResponseBody
    public List<ProjectStar> countEvaStar(String param,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        return  evaluateService.countEvaStar(param,areaid,admin);
    }
    @RequestMapping("/evaluates")
    public String evaluates(){
        return "producing";
    }
     @RequestMapping("/evaluatess")
     public String evaluatess(){
        return "/Alert/producing";

  }
  @RequestMapping("/producing_add")
  public String producingadd(){
      return "/Alert/producing_add";

  }

}
